//
//  TMApplyMoneyBackController.m
//  国学培训用户端
//
//  Created by Tao Li on 2018/9/4.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMApplyMoneyBackController.h"
#import "TMUserViewModel.h"
@interface TMApplyMoneyBackController ()<UITextFieldDelegate,UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UITextField *phonetf;
@property (weak, nonatomic) IBOutlet UITextView *reasonTextview;
@property (weak, nonatomic) IBOutlet UILabel *placelabel;
@property (nonatomic, strong) TMUserViewModel *viewModel;
@end

@implementation TMApplyMoneyBackController
- (IBAction)backBtn:(UIButton *)sender {
    if (![SPToolSet isMobileNumber:self.phonetf.text]) {
        [TMProgressHUD showErrorWithStyleDarkStatus:@"请输入正确的手机号！"];
        return;
    }
    if (self.reasonTextview.text.length == 0 || !self.reasonTextview.text) {
        [TMProgressHUD showInfoWithStyleDarkStatus:@"请输入申请退款理由！"];
        return;
    }
    [self.viewModel getMoneyBackWith:@{@"phone":self.phonetf.text,@"content":self.reasonTextview.text,@"id":@(self.oid),@"uid":@([TMUserManager deaufatManager].userModel.uid),@"token":[TMUserManager deaufatManager].userModel.token} Success:^(id responseObject) {
        [self.navigationController popViewControllerAnimated:YES];
    } AndFiled:^(NSString *error) {
        
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"申请退款";
    self.viewModel = [[TMUserViewModel alloc]init];
    self.nameLabel.text = [NSString stringWithFormat:@"商品名称：%@", self.bussinessName];
    self.phonetf.delegate = self;
    self.reasonTextview.delegate = self;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insert:) name:UITextViewTextDidChangeNotification object:nil];
    self.reasonTextview.layer.borderWidth = 1.0f;
    self.reasonTextview.layer.borderColor = [UIColor hx_colorWithHexRGBAString:@"#EEEEEE"].CGColor;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)insert:(UITextView *)textview{
    if (self.reasonTextview.text.length>0) {
        self.placelabel.hidden = YES;
    }else{
        self.placelabel.hidden = NO;
    }
}
- (void)textViewDidChange:(UITextView *)textView{
    if (textView.text.length >= 100) {
        textView.text = [textView.text substringToIndex:100];
        [TMProgressHUD showInfoWithStyleDarkStatus:@"限制100字！"];
    }
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if ([self.phonetf isFirstResponder]) {
        [self.phonetf resignFirstResponder];
    }
    return YES;
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return false;
    }
    return true;
}


@end
